Skip to content

Conversation

@malkovitc
Copy link

PR Checklist

PR Type

  • Bugfix
  • Feature

What is the current behavior?

Issue Number: #16095

setGlobalPrefix() only accepts a single string prefix. Users who need to expose the same API under multiple base paths (e.g., for different deployment environments) previously used regex-style prefixes like (prefixOne|prefixTwo), which are no longer supported by path-to-regexp v8 in NestJS v11.

What is the new behavior?

setGlobalPrefix() now accepts either a string or an array of strings:

// Single prefix (existing behavior)
app.setGlobalPrefix('api');

// Multiple prefixes (new)
app.setGlobalPrefix(['api', 'v1']);
// Routes will be registered under both /api/... and /v1/...

This provides a migration path for users who previously relied on regex-style prefixes.

Changes:

  • Updated INestApplication.setGlobalPrefix() interface to accept string | string[]
  • Added getGlobalPrefixes() method to ApplicationConfig to retrieve all prefixes
  • Updated RoutePathFactory to generate paths for each prefix in the array
  • Added unit tests for the new functionality

Does this PR introduce a breaking change?

  • Yes
  • No

The change is backward compatible - existing code using a single string prefix will continue to work.

@malkovitc
Copy link
Author

Closing to address additional issues found during review. Will reopen after fixing middleware and error handler support for multiple prefixes.

@malkovitc malkovitc closed this Dec 21, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 148c31b6-e053-4080-8c50-4316daa859cb

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 89.688%

Totals Coverage Status
Change from base Build e3800a39-758b-42fd-9609-068501388108: 0.004%
Covered Lines: 7419
Relevant Lines: 8272

💛 - Coveralls

@malkovitc
Copy link
Author

Fixed and reopened as #16102 with additional support for middleware path extraction with multiple prefixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants